Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

feat: use archive nodes to query attestations #571

Merged
merged 18 commits into from
Nov 6, 2023

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Oct 31, 2023

Overview

Supports querying for historical data when getting attestations that are pruned.

Would allow deploying the contract and also relay attestations if the corresponding valset got pruned via getting it from an archive node.

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Summary by CodeRabbit

  • New Features

    • Enhanced querying capabilities with new functions to retrieve historical attestations and valsets by nonce and height.
    • Introduced a fallback mechanism in the ProcessAttestation function to recover from failed valset queries.
    • Added new flags FlagCoreRPCHost and FlagCoreRPCPort to specify the RPC address host and port.
  • Refactor

    • Renamed the variable querier to appQuerier for clarity.
    • Modified the getStartingValset function to use the tmQuerier and appQuerier instances.
  • Tests

    • Added new test functions to validate the new query functions and fallback mechanism.
  • Bug Fixes

    • Added error handling in getStartingValset to handle cases where the valset cannot be retrieved from the node state.

@rach-id rach-id added enhancement New feature or request relayer relayer related labels Oct 31, 2023
@rach-id rach-id self-assigned this Oct 31, 2023
@rach-id rach-id requested a review from evan-forbes as a code owner October 31, 2023 12:58
@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2023

Codecov Report

Merging #571 (6de00da) into main (616068c) will decrease coverage by 2.06%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #571      +/-   ##
==========================================
- Coverage   34.84%   32.78%   -2.06%     
==========================================
  Files          27       27              
  Lines        2230     2370     +140     
==========================================
  Hits          777      777              
- Misses       1360     1500     +140     
  Partials       93       93              
Files Coverage Δ
relayer/relayer.go 0.00% <0.00%> (ø)
rpc/app_querier.go 0.00% <0.00%> (ø)

@rach-id
Copy link
Member Author

rach-id commented Oct 31, 2023

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Oct 31, 2023

Warning

Rate Limit Exceeded

@sweexordious has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 12 minutes and 38 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per repository.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between bda6cb5 and 6de00da.

Walkthrough

The changes in this update focus on enhancing the querying capabilities of the AppQuerier struct in the rpc package. Historical data retrieval is now possible with the introduction of new functions to query historical attestations and valsets by nonce and height. Error handling and fallback mechanisms have been added to handle cases where the valset cannot be retrieved from the node state. Additionally, new flags have been introduced to specify the RPC address host and port for the deployment process. Several test suites and functions have been added to validate the new features.

Changes

File(s) Summary
cmd/blobstream/deploy/cmd.go Renamed the variable querier to appQuerier and updated its references. Added a new variable tmQuerier of type rpc.TmQuerier. Started and stopped the tmQuerier instance. Modified the getStartingValset function to use the tmQuerier and appQuerier instances. Added error handling and fallback logic in getStartingValset to handle cases where the valset cannot be retrieved from the node state. Updated the return values of getStartingValset to return the valset or an error.
cmd/blobstream/deploy/config.go Introduced two new flags, FlagCoreRPCHost and FlagCoreRPCPort, to specify the RPC address host and port. Updated the deployConfig struct to include the coreRPC field representing the RPC address. Modified the parseDeployFlags function to parse the new flags and populate the coreRPC field accordingly.
cmd/blobstream/deploy/errors.go Introduced two new global variables: ErrNotFound and ErrUnmarshallValset. Changed the error message for ErrUnmarshallValset from "couldn't unmarsall valset" to "couldn't unmarshall valset".
e2e/scripts/deploy_blobstream_contract.sh Added two new command-line arguments --core.rpc.host and --core.rpc.port to specify the host and port for the Core RPC connection during the deployment of the Blobstream contract.
relayer/relayer.go Introduced a fallback mechanism in the ProcessAttestation function of the Relayer struct. If querying the last valset before a nonce fails, it first tries to recover by querying the valset from the P2P network. If that also fails, it falls back to using an archive node to query the valset. The function now returns an error if both attempts to query the valset fail.
rpc/app_querier.go Introduced several new functions to the AppQuerier struct in the rpc package. These functions allow querying historical attestations and valsets by nonce and height. Added a new global variable BlocksIn20DaysPeriod.
rpc/errors.go Introduced two new error variables: ErrNotFound and ErrCouldntReachSpecifiedHeight.
.../orchestrator/orchestrator_test.go Added the Pruning field with the value "default" to the test configuration. Modified the TimeoutCommit field to have a value of 5 milliseconds in the test configuration.
.../orchestrator/suite_test.go Added import for the "time" package. Modified the TimeIotaMs field value from 1 to 1. Added the Pruning field with the value "default". Added the TimeoutCommit field with the value 5 * time.Millisecond.
.../relayer/relayer_test.go Added the Pruning field with the value "default" to the test configuration. Modified the TimeoutCommit field to be set to 5 milliseconds.
rpc/app_historic_querier_test.go Added test functions to the HistoricQuerierTestSuite struct in the rpc_test package. The test functions make use of the rpc.NewAppQuerier function to create an instance of AppQuerier and test various query functions. The functions being tested include QueryHistoricAttestationByNonce, QueryRecursiveHistoricAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryHistoricalLastValsetBeforeNonce, and QueryRecursiveHistoricalLastValsetBeforeNonce. The tests involve querying historical attestations and valsets by nonce and height.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
rpc/historic_suite_test.go Added a new test suite called HistoricQuerierTestSuite in the rpc_test package. Set up a test environment with a Celestia network and initialized some parameters. The test suite includes a single test function called TestHistoricQueriers. The changes include importing new packages, defining new types and variables, and setting up the test environment.
testing/celestia_network.go Introduced new fields to the CelestiaNetworkParams struct: Pruning of type string and TimeoutCommit of type time.Duration. Updated the DefaultCelestiaNetworkParams function to set default values for the new fields. Updated the NewCelestiaNetwork function to use the params.Pruning value for the appConf.Pruning field and the params.TimeoutCommit value for the tmCfg.Consensus.TimeoutCommit field.
rpc/app_historic_querier_test.go Added test functions TestQueryHistoricAttestationByNonce, TestQueryRecursiveHistoricAttestationByNonce, TestQueryHistoricalLatestAttestationNonce, TestQueryHistoricalValsetByNonce, TestQueryHistoricalLastValsetBeforeNonce, and TestQueryRecursiveHistoricalLastValsetBeforeNonce to the HistoricQuerierTestSuite in the rpc_test package. These functions test various query functions of the appQuerier object. No changes to the signatures or global data structures.
rpc/historic_suite_test.go Added a new test suite HistoricQuerierTestSuite and a corresponding test function TestHistoricQueriers. Also added a new function setupAppQuerier that sets up an AppQuerier instance and starts it. The HistoricQuerierTestSuite struct has fields for Network, EncConf, and Logger. The SetupSuite function initializes these fields and sets the rpc.BlocksIn20DaysPeriod variable. The test suite is run using suite.Run. The setupAppQuerier function creates a new AppQuerier instance, starts it, and cleans it up after the test.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite in the relayer_test package. The test waits for a specific height on the Celestia network, queries the latest valset, and then queries attestations until an error occurs. It creates a new att object, queries a commitment, calculates a data root tuple root sign bytes, and processes a data commitment event. Finally, it calls the ProcessAttestation function on the Relayer with the att object.
relayer/historic_suite_test.go Added a new test suite called HistoricalRelayerTestSuite in the relayer_test package. The test suite sets up a test environment with a test node, orchestrator, and relayer. It also defines two test functions: SetupSuite and TearDownSuite. The SetupSuite function initializes the test environment and deploys a contract. The TearDownSuite function closes the test node. The diff also adds a new test function called TestHistoricRelayer that runs the HistoricalRelayerTestSuite test suite.
rpc/app_querier.go Introduced several new functions to query historical data in the AppQuerier struct. These functions allow querying attestation and valset data at specific heights or recursively going back in history. The diff also adds a new global variable BlocksIn20DaysPeriod and imports additional packages. Overall, the changes enhance the querying capabilities of the AppQuerier and provide access to historical data.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
rpc/historic_suite_test.go Added a new test suite HistoricQuerierTestSuite and a corresponding test function TestHistoricQueriers. Also added a new function setupAppQuerier that sets up an AppQuerier instance and starts it. The HistoricQuerierTestSuite struct has fields for Network, EncConf, and Logger. The SetupSuite function initializes these fields and sets the rpc.BlocksIn20DaysPeriod variable. The test suite is run using suite.Run. The setupAppQuerier function creates a new AppQuerier instance, starts it, and cleans it up after the test.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.
rpc/app_querier.go Added new functions QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce. Added a new global variable BlocksIn20DaysPeriod. Modified the signatures of several existing functions to return errors.
relayer/historic_relayer_test.go Added a new test function TestProcessHistoricAttestation to the HistoricalRelayerTestSuite struct. This test function waits for a specific height, queries the latest valset, waits for the valset to be pruned, signs a test data commitment, and processes the data commitment using the relayer. The test verifies that the relayer is able to relay using a pruned valset. No alterations to exported functions, global data structures, global variables, interfaces, return values, or thrown exceptions are made.

🐇🍂
As the leaves fall, so does the old code,
Making way for the new, along the same road.
With queries that dive into history's hold,
And tests that ensure the results are gold.
As we hop into November's fold,
Let's celebrate these changes bold! 🎉🥕


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a61dc19 and a8ed811.
Files selected for processing (7)
  • cmd/blobstream/deploy/cmd.go (3 hunks)
  • cmd/blobstream/deploy/config.go (5 hunks)
  • cmd/blobstream/deploy/errors.go (1 hunks)
  • e2e/scripts/deploy_blobstream_contract.sh (1 hunks)
  • relayer/relayer.go (1 hunks)
  • rpc/app_querier.go (7 hunks)
  • rpc/errors.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • cmd/blobstream/deploy/errors.go
  • rpc/errors.go
Additional comments: 12
relayer/relayer.go (1)
  • 148-161: The fallback mechanism for querying the last valset before a nonce is well implemented. It first tries to recover by querying the valset from the P2P network. If that fails, it falls back to using an archive node to query the valset. The function now returns an error if both attempts to query the valset fail. This is a good practice for error handling and recovery.
cmd/blobstream/deploy/config.go (5)
  • 17-24: The new flags FlagCoreRPCHost and FlagCoreRPCPort are introduced correctly.

  • 28-32: The new flags are added to the command with default values. Ensure that these default values are appropriate for your use case.

  • 52-61: The deployConfig struct is updated to include the coreRPC field. This change is consistent with the new flags introduced.

  • 80-93: The new flags are parsed correctly and error handling is in place.

  • 120-123: The coreRPC field is populated using the parsed values of the new flags. The format of the coreRPC string seems to be correct.

e2e/scripts/deploy_blobstream_contract.sh (1)
  • 68-72: The addition of the --core.rpc.host and --core.rpc.port flags to the deployment command is consistent with the PR summary. Ensure that these flags are correctly handled in the blobstream deploy command and that the RPC connection is properly established and used.
cmd/blobstream/deploy/cmd.go (1)
  • 142-170: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [146-198]

The getStartingValset function has been updated to handle different cases for the startingNonce argument. The error handling and fallback logic are well implemented. However, the function could be simplified by extracting the repeated code into a separate function.

rpc/app_querier.go (4)
  • 22-22: The global variable BlocksIn20DaysPeriod is calculated based on appconsts.TimeoutCommit.Seconds(). Ensure that appconsts.TimeoutCommit.Seconds() is always a constant and not subject to change during runtime. If it can change, consider moving this calculation into a function to ensure the value is always accurate.

  • 73-96: The function QueryHistoricalAttestationByNonce queries an attestation by nonce from the state machine at a certain height. It uses the grpc.Header function to retrieve the header from the response. Ensure that the header is used correctly in the rest of the code.

  • 139-154: The function QueryHistoricalLatestAttestationNonce queries the historical latest attestation nonce from the state machine at a certain nonce. It uses the grpc.Header function to retrieve the header from the response. Ensure that the header is used correctly in the rest of the code.

  • 212-227: The function QueryHistoricalValsetByNonce queries a historical valset by nonce. It uses the QueryHistoricalAttestationByNonce function to get the attestation and then checks if it's a valset. Ensure that all attestations that are valsets can be correctly unmarshalled into the Valset type.

cmd/blobstream/deploy/cmd.go Outdated Show resolved Hide resolved
rpc/app_querier.go Outdated Show resolved Hide resolved
rpc/app_querier.go Outdated Show resolved Hide resolved
rpc/app_querier.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a8ed811 and e1d3468.
Files selected for processing (2)
  • cmd/blobstream/deploy/cmd.go (3 hunks)
  • rpc/app_querier.go (7 hunks)
Additional comments: 15
cmd/blobstream/deploy/cmd.go (6)
  • 43-56: The appQuerier instance is started and stopped correctly. The error handling and logging are also done properly.

  • 58-68: The tmQuerier instance is started and stopped correctly. The error handling and logging are also done properly.

  • 70-75: The error handling and logging in the getStartingValset function call are done correctly.

  • 146-156: The getStartingValset function has been updated to handle errors when querying the latest valset. If an error occurs, it attempts to query historical data. This is a good fallback mechanism.

  • 160-168: The function also handles errors when querying attestations by nonce. If an error occurs, it attempts to query historical data. This is a good fallback mechanism.

  • 176-195: The function handles errors when parsing the starting nonce and querying historical attestations by nonce. If the attestation is of type types.Valset, it returns the value. If it's of type types.DataCommitment, it queries the last valset before the nonce. This is a good way to handle different types of attestations.

rpc/app_querier.go (9)
  • 2-13: The import statements are well organized and there are no unused imports. The import paths are correct.

23:
The global variable BlocksIn20DaysPeriod is calculated correctly. However, it's better to add a comment to explain what it represents and why it's calculated this way.

  • 25-27: The AppQuerier struct is well defined with appropriate fields. The comments provide a clear explanation of its purpose.

  • 74-97: The QueryHistoricalAttestationByNonce function is correctly implemented. It queries an attestation by nonce from the state machine at a certain height. The error handling is also done correctly.

  • 99-130: The QueryRecursiveHistoricalAttestationByNonce function is correctly implemented. It queries an attestation by nonce from the state machine by going over the history step by step starting from a certain height. The error handling and the use of context with timeout are also done correctly.

  • 147-162: The QueryHistoricalLatestAttestationNonce function is correctly implemented. It queries the historical latest attestation nonce from the state machine at a certain height. The error handling is also done correctly.

  • 220-236: The QueryHistoricalValsetByNonce function is correctly implemented. It queries a historical valset by nonce. The error handling is also done correctly.

  • 257-286: The QueryRecursiveLatestValset function is correctly implemented. It queries the latest recorded valset in the state machine in history. The error handling and the use of context with timeout are also done correctly.

  • 305-319: The QueryHistoricalLastValsetBeforeNonce function is correctly implemented. It returns the last historical valset before nonce for a certain height. The error handling is also done correctly.

  • 321-347: The QueryRecursiveHistoricalLastValsetBeforeNonce function is correctly implemented. It recursively looks for the last historical valset before nonce for a certain height until genesis. The error handling and the use of context with timeout are also done correctly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e1d3468 and 01f8e74.
Files selected for processing (7)
  • orchestrator/orchestrator_test.go (1 hunks)
  • orchestrator/suite_test.go (2 hunks)
  • relayer/relayer_test.go (1 hunks)
  • rpc/app_historic_querier_test.go (1 hunks)
  • rpc/app_querier.go (7 hunks)
  • rpc/historic_suite_test.go (1 hunks)
  • testing/celestia_network.go (2 hunks)
Additional comments: 25
relayer/relayer_test.go (1)
  • 68-74: The Pruning field is set to "default" and TimeoutCommit is set to 5 milliseconds. Ensure that these settings are appropriate for your use case. The TimeoutCommit value seems quite low, which could lead to frequent timeouts if the system is under heavy load. Consider increasing this value if you experience issues.
orchestrator/orchestrator_test.go (1)
  • 206-212: The test configuration has been updated to include a Pruning field with the value "default" and the TimeoutCommit field has been modified to have a value of 5 milliseconds. Ensure that these changes are compatible with the rest of the test suite and the application as a whole.
orchestrator/suite_test.go (2)
  • 3-9: The "time" package has been added to the import list. Ensure that it is used in the codebase.

  • 35-37: The "TimeIotaMs" field value has been set to 1, the "Pruning" field has been added with the value "default", and the "TimeoutCommit" field has been added with the value 5 * time.Millisecond. Ensure that these changes are compatible with the rest of the codebase.

testing/celestia_network.go (3)
  • 42-48: The CelestiaNetworkParams struct has been extended with two new fields: Pruning and TimeoutCommit. Ensure that these fields are properly used and initialized throughout the codebase.

  • 51-57: The DefaultCelestiaNetworkParams function has been updated to set default values for the new fields. Ensure that these default values are appropriate for your use case.

  • 79-84: The NewCelestiaNetwork function has been updated to use the new params.Pruning and params.TimeoutCommit values. This is a good use of the new parameters, as it allows for more flexible configuration of the CelestiaNetwork.

rpc/historic_suite_test.go (3)
  • 1-20: The import statements are well organized and separated by functionality. Good use of aliasing to avoid naming conflicts.

  • 22-27: The HistoricQuerierTestSuite struct is well defined with all necessary fields for the test suite.

  • 49-51: The TestHistoricQueriers function is correctly defined and runs the test suite as expected.

rpc/app_querier.go (15)
  • 2-13: The import section looks fine. All the imported packages are being used in the code.

  • 20-27: The global variable BlocksIn20DaysPeriod is defined and the AppQuerier struct is declared. The struct has fields for the RPC address, a gRPC client connection, a logger, and an encoding configuration.

  • 71-72: The QueryAttestationByNonce function is correctly implemented. It queries an attestation by nonce from the state machine and returns it.

  • 74-97: The QueryHistoricalAttestationByNonce function is correctly implemented. It queries an attestation by nonce from the state machine at a certain height and returns it.

  • 99-133: The QueryRecursiveHistoricalAttestationByNonce function is correctly implemented. It queries an attestation by nonce from the state machine by going over the history step by step starting from a certain height and returns it.

  • 71-137: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [135-147]

The QueryLatestAttestationNonce function is correctly implemented. It queries the latest attestation nonce from the state machine and returns it.

  • 150-164: The QueryHistoricalLatestAttestationNonce function is correctly implemented. It queries the historical latest attestation nonce from the state machine at a certain height and returns it.

  • 220-221: The QueryValsetByNonce function is correctly implemented. It queries a valset by nonce and returns it.

  • 223-238: The QueryHistoricalValsetByNonce function is correctly implemented. It queries a historical valset by nonce and returns it.

  • 257-258: The QueryLatestValset function is correctly implemented. It queries the latest recorded valset in the state machine and returns it.

  • 260-291: The QueryRecursiveLatestValset function is correctly implemented. It queries the latest recorded valset in the state machine in history and returns it.

  • 308-309: The QueryLastValsetBeforeNonce function is correctly implemented. It returns the last valset before a certain nonce.

  • 311-324: The QueryHistoricalLastValsetBeforeNonce function is correctly implemented. It returns the last historical valset before a certain nonce for a certain height.

  • 327-355: The QueryRecursiveHistoricalLastValsetBeforeNonce function is correctly implemented. It recursively looks for the last historical valset before a certain nonce for a certain height until genesis and returns it.

  • 358-360: The QueryLastUnbondingHeight function is correctly implemented. It queries the last unbonding height from the state machine and returns it.

rpc/historic_suite_test.go Outdated Show resolved Hide resolved
rpc/app_historic_querier_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 01f8e74 and 875df35.
Files selected for processing (2)
  • rpc/app_historic_querier_test.go (1 hunks)
  • rpc/historic_suite_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • rpc/app_historic_querier_test.go
Additional comments: 5
rpc/historic_suite_test.go (5)
  • 1-20: Imports look good, no unused or missing imports detected.

  • 22-27: The HistoricQuerierTestSuite struct is well defined with necessary fields.

  • 29-47: The SetupSuite function is correctly setting up the test suite. It's good to see that error handling is in place for WaitForHeightWithTimeout.

  • 49-51: The test suite is correctly run using suite.Run.

  • 53-64: The setupAppQuerier function correctly sets up and starts an AppQuerier instance. It's good to see that cleanup is being handled using s.T().Cleanup.

Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do all of these need to be expoesed by the api? also can we not use latest and last? similar to our other previous discussions around this I think it would be good to just use Last and earliest.
QueryHistoricalAttestationByNonce, QueryRecursiveHistoricalAttestationByNonce, QueryHistoricalLatestAttestationNonce, QueryHistoricalValsetByNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, QueryRecursiveHistoricalLastValsetBeforeNonce.

these names are very confusing imo

Comment on lines +312 to +328
func (aq *AppQuerier) QueryHistoricalLastValsetBeforeNonce(ctx context.Context, nonce uint64, height uint64) (*celestiatypes.Valset, error) {
queryClient := celestiatypes.NewQueryClient(aq.clientConn)
var header metadata.MD
resp, err := queryClient.LatestValsetRequestBeforeNonce(
metadata.AppendToOutgoingContext(ctx, cosmosgrpc.GRPCBlockHeightHeader, strconv.FormatUint(height, 10)),
&celestiatypes.QueryLatestValsetRequestBeforeNonceRequest{Nonce: nonce},
grpc.Header(&header),
)
if err != nil {
return nil, err
}

return resp.Valset, nil
}

// QueryRecursiveHistoricalLastValsetBeforeNonce recursively looks for the last historical valset before nonce for a certain height until genesis.
func (aq *AppQuerier) QueryRecursiveHistoricalLastValsetBeforeNonce(ctx context.Context, nonce uint64, height uint64) (*celestiatypes.Valset, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are both of these used independently, or do we only ever call one of these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of them queries at an exact height, the other goes range by range of blocks to find the attestation. So yes, both is used

@rach-id rach-id mentioned this pull request Nov 2, 2023
@rach-id
Copy link
Member Author

rach-id commented Nov 2, 2023

I prefer to do these renames:

do all of these need to be expoesed by the api? also can we not use latest and last? similar to our other previous discussions around this I think it would be good to just use Last and earliest.

in a separate PR. Since that would require renaming different parts of the implementation and I don't want to include all of that in this PR.

@rach-id
Copy link
Member Author

rach-id commented Nov 2, 2023

@evan-forbes What do you think about:

  • QueryRecursiveHistoricalLastValsetBeforeNonce => FindLastHistoricalValsetBeforeNonceRecursive
  • QueryHistoricalLastValsetBeforeNonce => QueryLastHistoricalValsetBeforeNonce

?

evan-forbes
evan-forbes previously approved these changes Nov 2, 2023
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the api increase isn't that big of deal since its just the orchestrator/relayer, and might require a larger PR to fix properly. This is just something that was sticking was all. Ideally I think it would be great to isolate the actual queries made to the app in the app querier, and then refactor and separate the logic for getting the last, earliest, before nonce / after nonce

it would be nice to be consistent with last and earliest like we are doing in the app, as I often get confused since I'm not 100% sure we're using latest consistently. I could also just not be understanding latest.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 875df35 and 7720553.
Files selected for processing (3)
  • relayer/historic_relayer_test.go (1 hunks)
  • relayer/historic_suite_test.go (1 hunks)
  • rpc/app_querier.go (7 hunks)
Additional comments: 6
relayer/historic_suite_test.go (1)
  • 1-66: The test suite and test case setup look good. The HistoricalRelayerTestSuite is well-structured and the SetupSuite and TearDownSuite methods are correctly implemented. The TestHistoricRelayer function correctly runs the test suite. However, ensure that the HistoricalRelayerTestSuite is being used in the right context and that the test cases within it are correctly testing the functionality they are supposed to.
rpc/app_querier.go (5)
  • 2-13: The new imports seem to be necessary for the new functions and types used in this file. Ensure that all these packages are included in your dependencies.

  • 71-133: The new functions QueryHistoricalAttestationByNonce and QueryRecursiveHistoricalAttestationByNonce are well implemented. They use the gRPC client to query attestations by nonce at a specific height or recursively. The error handling and context cancellation are correctly implemented.

  • 257-296: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [147-292]

The new functions QueryHistoricalLatestAttestationNonce, QueryRecursiveLatestValset, QueryHistoricalLastValsetBeforeNonce, and QueryRecursiveHistoricalLastValsetBeforeNonce are well implemented. They use the gRPC client to query attestations and valsets at a specific height or recursively. The error handling and context cancellation are correctly implemented.

  • 308-349: The new function QueryRecursiveHistoricalLastValsetBeforeNonce is well implemented. It uses the gRPC client to query valsets at a specific height or recursively. The error handling and context cancellation are correctly implemented.

  • 351-353: The new function QueryLastUnbondingHeight is well implemented. It uses the gRPC client to query the last unbonding height from the state machine. The error handling is correctly implemented.

rpc/app_querier.go Outdated Show resolved Hide resolved
relayer/historic_relayer_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7720553 and c5e3ae7.
Files selected for processing (2)
  • relayer/historic_relayer_test.go (1 hunks)
  • rpc/app_querier.go (7 hunks)
Files skipped from review due to trivial changes (1)
  • relayer/historic_relayer_test.go
Additional comments: 12
rpc/app_querier.go (12)
  • 2-13: The import statements are well organized and there are no unused imports.

  • 20-25: The global variable BlocksIn20DaysPeriod is well defined and the comment explains its purpose clearly.

  • 27-29: The AppQuerier struct is well defined with appropriate fields.

  • 76-98: The QueryHistoricalAttestationByNonce function is well implemented with proper error handling. It queries an attestation by nonce from the state machine at a certain height.

  • 101-135: The QueryRecursiveHistoricalAttestationByNonce function is well implemented with proper error handling and a timeout context. It queries an attestation by nonce from the state machine by going over the history step by step starting from a certain height.

  • 152-166: The QueryHistoricalLatestAttestationNonce function is well implemented with proper error handling. It queries the historical latest attestation nonce from the state machine at a certain height.

  • 169-171: The QueryDataCommitmentByNonce function is well implemented with proper error handling. It queries a data commitment by its nonce.

  • 225-240: The QueryHistoricalValsetByNonce function is well implemented with proper error handling. It queries a historical valset by nonce.

  • 262-293: The QueryRecursiveLatestValset function is well implemented with proper error handling and a timeout context. It queries the latest recorded valset in the state machine in history.

  • 313-326: The QueryHistoricalLastValsetBeforeNonce function is well implemented with proper error handling. It returns the last historical valset before nonce for a certain height.

  • 329-351: The QueryRecursiveHistoricalLastValsetBeforeNonce function is well implemented with proper error handling and a timeout context. It recursively looks for the last historical valset before nonce for a certain height until genesis.

  • 353-355: The QueryLastUnbondingHeight function is well implemented with proper error handling. It queries the last unbonding height from the state machine.

@rach-id
Copy link
Member Author

rach-id commented Nov 2, 2023

@evan-forbes is ready for review again, only added a relayer test with an archive node.

@rach-id rach-id requested a review from evan-forbes November 2, 2023 21:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c5e3ae7 and bda6cb5.
Files selected for processing (2)
  • relayer/relayer.go (1 hunks)
  • rpc/app_querier.go (7 hunks)
Additional comments: 15
rpc/app_querier.go (11)
  • 2-13: The import statements are well organized and there are no unused imports.

  • 20-25: The global variable BlocksIn20DaysPeriod is well defined and the comment explains its purpose clearly.

  • 27-29: The AppQuerier struct is well defined with appropriate fields.

  • 76-98: The QueryHistoricalAttestationByNonce function is well implemented with proper error handling. It queries an attestation by nonce from the state machine at a certain height.

  • 101-134: The QueryRecursiveHistoricalAttestationByNonce function is well implemented with proper error handling and a timeout context. It queries an attestation by nonce from the state machine by going over the history step by step starting from height.

  • 151-165: The QueryHistoricalLatestAttestationNonce function is well implemented with proper error handling. It queries the historical latest attestation nonce from the state machine at a certain nonce.

  • 224-239: The QueryHistoricalValsetByNonce function is well implemented with proper error handling. It queries a historical valset by nonce.

  • 261-291: The QueryRecursiveLatestValset function is well implemented with proper error handling and a timeout context. It queries the latest recorded valset in the state machine in history.

  • 311-324: The QueryHistoricalLastValsetBeforeNonce function is well implemented with proper error handling. It returns the last historical valset before nonce for a certain height.

  • 327-351: The QueryRecursiveHistoricalLastValsetBeforeNonce function is well implemented with proper error handling and a timeout context. It recursively looks for the last historical valset before nonce for a certain height until genesis.

  • 353-355: The QueryLastUnbondingHeight function is well implemented with proper error handling. It queries the last unbonding height from state machine.

relayer/relayer.go (4)
  • 145-162: The error handling and fallback logic for retrieving the previous valset is well implemented. It first tries to get the valset from the app querier, then falls back to the P2P network, and finally tries to get it from an archive node. This ensures that the function can still retrieve the valset even if some sources fail. However, it's important to note that querying from an archive node can be slow and resource-intensive, so it should be used as a last resort.

  • 163-164: The type switch statement is a good way to handle different types of attestations. It ensures that the correct processing logic is used for each type.

  • 145-164: > Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [165-211]

The logic for processing the attestations is well implemented. It retrieves the necessary data, validates it, and then submits it to the EVM client. However, it's important to ensure that the EVM client is properly handling these transactions and that any errors are being correctly propagated back to this function.

  • 145-164: > Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [212-214]

The default case in the type switch statement correctly handles unknown attestation types by returning an error. This is a good practice as it ensures that the function fails fast when it encounters an unexpected input.

@rach-id rach-id changed the title feat: use historical data to query attestations feat: use archive nodes to query attestations Nov 3, 2023
@rach-id rach-id merged commit 87d842a into celestiaorg:main Nov 6, 2023
18 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request relayer relayer related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants